home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qlist.h.z / qlist.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  9.3 KB  |  213 lines

  1. /****************************************************************************
  2. ** $Id: qlist.h,v 2.5 1998/07/03 00:09:46 hanord Exp $
  3. **
  4. ** Definition of QList template/macro class
  5. **
  6. ** Created : 920701
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QLIST_H
  25. #define QLIST_H
  26.  
  27. #ifndef QT_H
  28. #include "qglist.h"
  29. #endif // QT_H
  30.  
  31.  
  32. #if defined(USE_MACROCLASS)
  33.  
  34. #include "qgeneric.h"
  35.  
  36. #if !defined(name2)
  37. #define name2(a,b)    name2_xx(a,b)
  38. #define name2_xx(a,b) a##b
  39. #endif
  40.  
  41. #if defined(DEFAULT_MACROCLASS)
  42. #define QListdeclare QListMdeclare
  43. #define QList QListM
  44. #endif
  45. #define QListM(type) name2(QListM_,type)
  46.  
  47. #define QListMdeclare(type)                              \
  48. class QListM(type) : public QGList                          \
  49. {                                          \
  50. public:                                          \
  51.     QListM(type)()            {}                      \
  52.     QListM(type)( const QListM(type) &l ) : QGList(l) {}              \
  53.    ~QListM(type)()            { clear(); }                  \
  54.     QListM(type) &operator=(const QListM(type) &l)                  \
  55.             { return (QListM(type)&)QGList::operator=(l); }          \
  56.     uint  count()   const        { return QGList::count(); }          \
  57.     bool  isEmpty() const        { return QGList::count() == 0; }      \
  58.     bool  insert( uint i, const type *d){ return QGList::insertAt(i,(GCI)d); }\
  59.     void  inSort( const type *d )    { QGList::inSort((GCI)d); }          \
  60.     void  append( const type *d )    { QGList::append((GCI)d); }          \
  61.     bool  remove( uint i )        { return QGList::removeAt(i); }          \
  62.     bool  remove()            { return QGList::remove((GCI)0); }    \
  63.     bool  remove( const type *d )    { return QGList::remove((GCI)d); }    \
  64.     bool  removeRef( const type *d )    { return QGList::removeRef((GCI)d); } \
  65.     void  removeNode( QLNode *n )    { QGList::removeNode(n); }          \
  66.     bool  removeFirst()            { return QGList::removeFirst(); }     \
  67.     bool  removeLast()            { return QGList::removeLast(); }      \
  68.     type *take( uint i )        { return (type *)QGList::takeAt(i); } \
  69.     type *take()            { return (type *)QGList::take(); }    \
  70.     type *takeNode( QLNode *n )        { return (type *)QGList::takeNode(n);}\
  71.     void  clear()            { QGList::clear(); }              \
  72.     int      find( const type *d )        { return QGList::find((GCI)d); }      \
  73.     int      findNext( const type *d )    { return QGList::find((GCI)d,FALSE);} \
  74.     int      findRef( const type *d )    { return QGList::findRef((GCI)d); }   \
  75.     int      findNextRef( const type *d ){ return QGList::findRef((GCI)d,FALSE);}\
  76.     uint  contains( const type *d ) const { return QGList::contains((GCI)d); }\
  77.     uint  containsRef( const type *d ) const                      \
  78.                     { return QGList::containsRef((GCI)d);}\
  79.     type *at( uint i )            { return (type *)QGList::at(i); }     \
  80.     int      at() const            { return QGList::at(); }          \
  81.     type *current()  const        { return (type *)QGList::get(); }     \
  82.     QLNode *currentNode()  const    { return QGList::currentNode(); }     \
  83.     type *getFirst() const        { return (type *)QGList::cfirst(); }  \
  84.     type *getLast()  const        { return (type *)QGList::clast(); }   \
  85.     type *first()            { return (type *)QGList::first(); }   \
  86.     type *last()            { return (type *)QGList::last(); }    \
  87.     type *next()            { return (type *)QGList::next(); }    \
  88.     type *prev()            { return (type *)QGList::prev(); }    \
  89.     void  toVector( QGVector *vec )const{ QGList::toVector(vec); }          \
  90. private:                                      \
  91.     void  deleteItem( GCI d ) { if ( del_item ) delete (type *)d; }          \
  92. }
  93.  
  94.  
  95. #if defined(DEFAULT_MACROCLASS)
  96. #define QListIteratordeclare QListIteratorMdeclare
  97. #define QListIterator QListIteratorM
  98. #endif
  99. #define QListIteratorM(type) name2(QListIteratorM_,type)
  100.  
  101. #define QListIteratorMdeclare(type)                          \
  102. class QListIteratorM(type) : public QGListIterator                  \
  103. {                                          \
  104. public:                                          \
  105.     QListIteratorM(type)(const QListM(type) &l) :QGListIterator((QGList &)l){}\
  106.    ~QListIteratorM(type)()    {}                          \
  107.     uint  count()   const     { return list->count(); }                  \
  108.     bool  isEmpty() const     { return list->count() == 0; }              \
  109.     bool  atFirst() const     { return QGListIterator::atFirst(); }          \
  110.     bool  atLast()  const     { return QGListIterator::atLast(); }          \
  111.     type *toFirst()          { return (type *)QGListIterator::toFirst(); }   \
  112.     type *toLast()          { return (type *)QGListIterator::toLast(); }    \
  113.     operator type *() const   { return (type *)QGListIterator::get(); }          \
  114.     type *current()   const   { return (type *)QGListIterator::get(); }          \
  115.     type *operator()()          { return (type *)QGListIterator::operator()();} \
  116.     type *operator++()          { return (type *)QGListIterator::operator++(); }\
  117.     type *operator+=(uint j)  { return (type *)QGListIterator::operator+=(j);}\
  118.     type *operator--()          { return (type *)QGListIterator::operator--(); }\
  119.     type *operator-=(uint j)  { return (type *)QGListIterator::operator-=(j);}\
  120.     QListIteratorM(type)& operator=(const QListIteratorM(type)&it)            \
  121.                   { QGListIterator::operator=(it); return *this; }\
  122. }
  123.  
  124. #endif // USE_MACROCLASS
  125.  
  126.  
  127. #if defined(USE_TEMPLATECLASS)
  128.  
  129. #if defined(DEFAULT_TEMPLATECLASS)
  130. #undef    QList
  131. #define QList QListT
  132. #endif
  133.  
  134. template<class type> class QListT : public QGList
  135. {
  136. public:
  137.     QListT()                {}
  138.     QListT( const QListT<type> &l ) : QGList(l) {}
  139.    ~QListT()                { clear(); }
  140.     QListT<type> &operator=(const QListT<type> &l)
  141.             { return (QListT<type>&)QGList::operator=(l); }
  142.     uint  count()   const        { return QGList::count(); }
  143.     bool  isEmpty() const        { return QGList::count() == 0; }
  144.     bool  insert( uint i, const type *d){ return QGList::insertAt(i,(GCI)d); }
  145.     void  inSort( const type *d )    { QGList::inSort((GCI)d); }
  146.     void  append( const type *d )    { QGList::append((GCI)d); }
  147.     bool  remove( uint i )        { return QGList::removeAt(i); }
  148.     bool  remove()            { return QGList::remove((GCI)0); }
  149.     bool  remove( const type *d )    { return QGList::remove((GCI)d); }
  150.     bool  removeRef( const type *d )    { return QGList::removeRef((GCI)d); }
  151.     void  removeNode( QLNode *n )    { QGList::removeNode(n); }
  152.     bool  removeFirst()            { return QGList::removeFirst(); }
  153.     bool  removeLast()            { return QGList::removeLast(); }
  154.     type *take( uint i )        { return (type *)QGList::takeAt(i); }
  155.     type *take()            { return (type *)QGList::take(); }
  156.     type *takeNode( QLNode *n )        { return (type *)QGList::takeNode(n); }
  157.     void  clear()            { QGList::clear(); }
  158.     int      find( const type *d )        { return QGList::find((GCI)d); }
  159.     int      findNext( const type *d )    { return QGList::find((GCI)d,FALSE); }
  160.     int      findRef( const type *d )    { return QGList::findRef((GCI)d); }
  161.     int      findNextRef( const type *d ){ return QGList::findRef((GCI)d,FALSE);}
  162.     uint  contains( const type *d ) const { return QGList::contains((GCI)d); }
  163.     uint  containsRef( const type *d ) const
  164.                     { return QGList::containsRef((GCI)d); }
  165.     type *at( uint i )            { return (type *)QGList::at(i); }
  166.     int      at() const            { return QGList::at(); }
  167.     type *current()  const        { return (type *)QGList::get(); }
  168.     QLNode *currentNode()  const    { return QGList::currentNode(); }
  169.     type *getFirst() const        { return (type *)QGList::cfirst(); }
  170.     type *getLast()  const        { return (type *)QGList::clast(); }
  171.     type *first()            { return (type *)QGList::first(); }
  172.     type *last()            { return (type *)QGList::last(); }
  173.     type *next()            { return (type *)QGList::next(); }
  174.     type *prev()            { return (type *)QGList::prev(); }
  175.     void  toVector( QGVector *vec )const{ QGList::toVector(vec); }
  176. private:
  177.     void  deleteItem( GCI d ) { if ( del_item ) delete (type *)d; }
  178. };
  179.  
  180.  
  181. #if defined(DEFAULT_TEMPLATECLASS)
  182. #undef    QListIterator
  183. #define QListIterator QListIteratorT
  184. #endif
  185.  
  186. template<class type> class QListIteratorT : public QGListIterator
  187. {
  188. public:
  189.     QListIteratorT(const QListT<type> &l) :QGListIterator((QGList &)l) {}
  190.    ~QListIteratorT()          {}
  191.     uint  count()   const     { return list->count(); }
  192.     bool  isEmpty() const     { return list->count() == 0; }
  193.     bool  atFirst() const     { return QGListIterator::atFirst(); }
  194.     bool  atLast()  const     { return QGListIterator::atLast(); }
  195.     type *toFirst()          { return (type *)QGListIterator::toFirst(); }
  196.     type *toLast()          { return (type *)QGListIterator::toLast(); }
  197.     operator type *() const   { return (type *)QGListIterator::get(); }
  198.     type *current()   const   { return (type *)QGListIterator::get(); }
  199.     type *operator()()          { return (type *)QGListIterator::operator()();}
  200.     type *operator++()          { return (type *)QGListIterator::operator++(); }
  201.     type *operator+=(uint j)  { return (type *)QGListIterator::operator+=(j);}
  202.     type *operator--()          { return (type *)QGListIterator::operator--(); }
  203.     type *operator-=(uint j)  { return (type *)QGListIterator::operator-=(j);}
  204.     QListIteratorT<type>& operator=(const QListIteratorT<type>&it)
  205.                   { QGListIterator::operator=(it); return *this; }
  206. };
  207.  
  208.  
  209. #endif // USE_TEMPLATECLASS
  210.  
  211.  
  212. #endif // QLIST_H
  213.